package com.zy.ems.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zy.ems.dao.QuestionDao;
import com.zy.ems.model.QuestionEntity;
import com.zy.ems.common.base.BaseDao;
import com.zy.ems.common.base.BaseService;
import com.zy.ems.common.page.PaginationResult;
import com.zy.ems.common.util.DateUtil;
import com.zy.ems.common.util.StringUtils;

@Service
@Transactional
public class QuestionService extends BaseService<QuestionEntity, Integer> {
    @Autowired
    private QuestionDao questionDao;

    @Override
    public BaseDao<QuestionEntity, Integer> getEntityDao() {
        return this.questionDao;
    }

    /**
     * 获取试题列表
     */
    public PaginationResult<QuestionEntity> getQuestionList(
            Map<String, Object> paramMap) {

        int start = StringUtils.parseInt(paramMap.get("start"));
        int size = StringUtils.parseInt(paramMap.get("size"));

        return this.questionDao.findPageList(paramMap, start, size);
    }

    /**
     * 添加试题，批量
     * 
     * @param questions
     */
    public void saveQuestions(List<QuestionEntity> questions) {
        for (QuestionEntity entity : questions) {
            entity.setCreateTime(DateUtil.nowTimeStamp());
            entity.setUpdateTime(DateUtil.nowTimeStamp());
        }

        this.questionDao.saveQuestions(questions);
    }

    /**
     * 软删除试题
     */
    public void deleteQuestion(List<Integer> ids) {
        this.questionDao.deleteQuestion(ids);
    }
}
